//窗口布局管理
function NW05_dw(fq) {
    this.fq = fq;//nw
    this.nw = fq.fq;
}

//对body进行布局.
NW05_dw.prototype.stDW = function () {
    this.dw(this.nw.st);
}

/**
 * 对jd内进行布局.调整儿子 
 * @param {对象} nwJD nw封装的节点对象
 */
NW05_dw.prototype.dw = function (nwJD) {

    if (nwJD.Jiedian.getAttributeNode('xddw') || nwJD.Jiedian.getAttributeNode('gddw')) {
        this.dw1(nwJD);
    }

    let _ErziM = nwJD.Jiedian.children;
    let _nwErzi;
    for (let i = 0; i < _ErziM.length; i++) {
        if (_ErziM[i].getAttributeNode('hlbj')) {
            continue;
        }
        switch (_ErziM[i].nodeName) {
            case 'PZ':
                continue;
            case 'DIV':
            case 'IFRAME':
            case 'BUJU':
            case 'BJ':
            case 'NR':
                _nwErzi = this.nw.cj(_ErziM[i]);

                // if (_ErziM[i].getAttributeNode('xddw') || _ErziM[i].getAttributeNode('gddw')) {
                //     this.dw1(_nwErzi);
                // }
                //针对iframe 和 nr节点，不再进行他们的儿子定位检测
                // if (_ErziM[i].nodeName == 'IFRAME' || _ErziM[i].nodeName == 'NR') {
                //     continue;
                // }
                this.dw(_nwErzi);//检测他的儿子.
        }

    }
}

//定位
NW05_dw.prototype.dw1 = function (nwDX) {
    let pz = this._ngj_hqPZ(nwDX);
    if (pz && pz.fw) {
        switch (pz.fw) {
            case 'zsj': pz.lx
                ? nwDX.ys.xy_zsj2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_zsj(pz.x, pz.y, pz.dw); break;
            case 'sz': pz.lx
                ? nwDX.ys.xy_sz2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_sz(pz.x, pz.y, pz.dw); break;
            case 'ysj': pz.lx
                ? nwDX.ys.xy_ysj2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_ysj(pz.x, pz.y, pz.dw); break;

            case 'zz': pz.lx
                ? nwDX.ys.xy_zz2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_zz(pz.x, pz.y, pz.dw); break;
            case 'yz': pz.lx
                ? nwDX.ys.xy_yz2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_yz(pz.x, pz.y, pz.dw); break;

            case 'zxj': pz.lx
                ? nwDX.ys.xy_zxj2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_zxj(pz.x, pz.y, pz.dw); break;
            case 'xz': pz.lx
                ? nwDX.ys.xy_xz2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_xz(pz.x, pz.y, pz.dw); break;
            case 'yxj': pz.lx
                ? nwDX.ys.xy_yxj2(pz.x, pz.y, pz.dw)
                : nwDX.ys.xy_yxj(pz.x, pz.y, pz.dw); break;

            case 'zzj':
                pz.lx
                    ? nwDX.ys.xy_zzj2(pz.x, pz.y, pz.dw)
                    : nwDX.ys.xy_zzj(pz.x, pz.y, pz.dw); break;
        }
    }

}

NW05_dw.prototype._ngj_hqPZ = function (nwJD) {
    let lx = 0;
    let _zhi = nwJD.jd.hqSXzhi('xddw');//相对定位
    if (!_zhi) {
        _zhi = nwJD.jd.hqSXzhi('gddw');//相对定位
        lx = 2;
    }
    if (_zhi) {
        //方位,x偏量,y偏量,单位
        let jg = { fw: null, x: 0, y: 0, dw: null, lx: lx };

        if (_zhi.indexOf(',')) {
            _zhi = _zhi.split(',');
            switch (_zhi.length) {
                case 4:
                    jg.dw = _zhi[3] ? _zhi[3] : 'px'
                case 3:
                    jg.y = _zhi[2] ? parseFloat(_zhi[2]) : 0
                case 2:
                    jg.x = _zhi[1] ? parseFloat(_zhi[1]) : 0
                case 1:
                    jg.fw = _zhi[0];
            }
        } else {
            jg.fw = _zhi
        }
        return jg;
    }
    return null;
}